<?php
namespace Index\Controller;
use Think\Controller;
use Think\Page;
class SouController extends Controller {
    public function index(){
        header("Content-Type:text/html;charset=UTF-8");
        $sou = I("get.sou");
        import("Vendor.Pscws.pscws4");
        $pscws = new \PSCWS4();
        $pscws->PSCWS4('utf8');
        $pscws->set_dict(CONF_PATH."etc/dict.utf8.xdb");
        $pscws->set_rule(CONF_PATH."etc/rules.utf8.ini");
        $pscws->set_ignore(true);
        $pscws->send_text($sou);
        $rt = $pscws->get_tops(5);
        if(empty($rt)){
            $rt[]['word'] = $sou;
        }
        $pscws->close();
        $m = M();
        $sql = "select a.*,b.user_name,b.AvatarUlr from wenti a join user b on a.sid = b.id where ";
        foreach($rt as $v) {
            $sql .= "text like '%{$v['word']}%'or ";
        }
        $sql = substr($sql, 0, -3);
        $ret = $m->query($sql);
        $pga = new Page(count($ret),5);
        $show = $pga->show();
        $sql = "select a.*,b.user_name,b.AvatarUlr from wenti a join user b on a.sid = b.id where ";
        foreach($rt as $v) {
            $sql .= "text like '%{$v['word']}%'or ";
        }
        $sql = substr($sql, 0, -3);
        $sql .= " limit {$pga->firstRow},{$pga->listRows}";
        $ret = $m->query($sql);
        $this->assign('ret', $ret);
        $this->assign('show', $show);
//        var_dump($ret);
        $this->display('index');
    }
}